package com.tttshaoqi.server.controller;

import com.tttshaoqi.annotation.Log;
import com.tttshaoqi.common.result.PageResult;
import com.tttshaoqi.common.result.Result;
import com.tttshaoqi.server.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author tttshaoqi
 * &#064;create 2025-04-23-17:13
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private OrderService orderService;

    /**
     * 分页查询
     * @param beginTime
     * @param endTime
     * @param status
     * @param number
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageQuery(LocalDateTime beginTime, LocalDateTime endTime, Integer status,
                                        Integer number, Integer page, Integer pageSize){
        log.info("订单信息分页查询");
        PageResult pageResult = orderService.page(beginTime,endTime,status,number,page,pageSize);
        return Result.success(pageResult);
    }

    /**
     * 修改订单状态
     */
    @Log
    @PostMapping("status/{status}")
    public Result status(@PathVariable Integer status,Integer id){
        log.info("修改订单状态:{}",status,id);
        orderService.update(status,id);
        return Result.success();
    }

    /**
     * 新增订单
     */
    @Log
    @PutMapping()
    public Result add(Integer id, BigDecimal price,String userName, String userPhone, String userID){
        log.info("新增订单信息:{},{},{},{}",id,userName,userPhone,userID);
        return orderService.add(id,price,userName,userPhone,userID);
    }
}
